package org.minos.edit.controller
{
	import org.aswing.JOptionPane;
	import org.ichow.debug.Debug;
	import org.minos.edit.controller.manager.FileManager;
	import org.minos.edit.EditFacate;
	import org.minos.edit.model.ClearProxy;
	import org.minos.edit.model.vo.DialogVO;
	import org.puremvc.as3.interfaces.INotification;
	import org.puremvc.as3.patterns.command.SimpleCommand;
	
	/**
	 * ...
	 * @author Minos
	 */
	public class NewFileCommand extends SimpleCommand
	{
		
		override public function execute( notification : INotification ) : void
		{
			super.execute( notification );
			//check current file
			if ( FileManager.getCurrentFile() != null )
			{
				//dialog box
				var dialog : DialogVO = new DialogVO( "提示" , "确认文件已经保存，新建文档会清空数据！！" , JOptionPane.YES | JOptionPane.NO );
				dialog.callback = callback;
				sendNotification( EditFacate.SHOW_DIALOG , dialog );
			}
			else
			{
				callback( JOptionPane.YES );
			}
			
			function callback( result : int ) : void
			{
				if ( result == JOptionPane.YES )
				{
					//clear..
					var cp : ClearProxy = facade.retrieveProxy( ClearProxy.NAME ) as ClearProxy;
					cp.clear();
					//new
					FileManager.setCurrentFile( FileManager.getFile( "new" , null , true ) );
					sendNotification( EditFacate.FILE_CHANGED , FileManager.getFile( "new" ) );
				}
			}
		
		}
	
	}

}